<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>倒计时</title>
</head>
<body>
	<div id="count-down">
		支付剩余<span id="min"></span>分钟<span id="sec"></span>秒
	</div>



	<script>
		window.onload=function() {
			function countDownTime(secs,minId,secId,fn) { 
				// 接收总秒数,分id(dom),秒id(dom),倒计时结束后的回调(非必须)
				var currTime=secs;
				var timer=0;
				var minDom=returnDom(minId);
				var secDom=returnDom(secId);
				timer=setInterval(function(){
					var min=parseInt(currTime/60);
					var sec=currTime%60;
					if(currTime==-1) {
						clearInterval(timer);
						if(fn && typeof fn ==='function') {
							fn();
						}
						return;
					}
					setHtml(minDom,min);
					setHtml(secDom,sec);
					--currTime;
				},1000);

				function returnDom(id) { //接收id或者dom元素,TODO未做容错处理
					return (typeof id==='string')?(document.getElementById(id)):id;
				}

				function setHtml(dom,time) {
					dom.innerHTML=addZero(time);
				}

				function addZero(num) {
					return num<10?'0'+num:num;
				}

			}
			countDownTime(75,'min','sec');
			// countDownTime(78,document.getElementById('min'),document.getElementById('sec'));

		}
	</script>
</body>
</html>